/*
 * Created on 20/11/2007
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.seginfo.httpfuzzer;

import java.util.Iterator;

import org.apache.log4j.Logger;
import org.seginfo.httpfuzzer.header.HeaderProperty;

/**
 * @author Matu
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CaseLogger {
	
	private Logger logger;
	
	/**
	 * 
	 */
	public CaseLogger() {
		this.logger = Logger.getLogger(this.getClass());
	}
	
	public synchronized void logCase(FuzzCase fuzzCase) {
		this.logger.info(">>> >>> >>> >>> CASE ID: " + fuzzCase.getId() + " <<< <<< <<< <<<");
		this.logger.info("Method: " + fuzzCase.getMethod());
		this.logger.info("Path: " + fuzzCase.getPath());
		this.logger.info("HTTP version: " + fuzzCase.getHttpVersion());
		Iterator properties = fuzzCase.getRequestProperties().iterator();
		while (properties.hasNext()) {
			HeaderProperty property = (HeaderProperty) properties.next();
			this.logger.info(property.getName() + ": " + property.getValue());
		}
		if (fuzzCase.getContent() != null) {
			this.logger.info("Content-Length: " + fuzzCase.getAlternativeContentLength());
			this.logger.info("Real content length: " + fuzzCase.getContent().length);
			this.logger.info("Content: " + new String(fuzzCase.getContent()));
		}
		this.logger.info("Server: " + fuzzCase.getServer());
		this.logger.info("Response code: " + fuzzCase.getStatus().getCode() + " (" + fuzzCase.getStatus().getName() + ")");
		String result = null;
		switch (fuzzCase.getResult()) {
			case FuzzCase.NORMAL:
				result = "Normal";
				break;
			case FuzzCase.CONNECTION_RESET:
				result = "Connection reset";
				break;
			case FuzzCase.CONNECTION_REFUSED:
				result = "Connection refused";
				break;
			case FuzzCase.NO_RESPONSE:
				result = "No response";
				break;
		}
		this.logger.info("Result: " + result);
	}

}
